/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "文件.h"

#include <windows.h>
#include <iostream>


void f_file_删除文件(const std::filesystem::path& path) {
	SHFILEOPSTRUCT fileOp;
	ZeroMemory(&fileOp, sizeof(fileOp));

	fileOp.wFunc = FO_DELETE; // 移动到回收站
	fileOp.pFrom = path.wstring().c_str();
	fileOp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT;

	int result = SHFileOperation(&fileOp);

	if (result) {
		std::cout<<"删除文件失败 \n";

		std::filesystem::remove(path);
	}
}





std::filesystem::path f_file_getUserHomeDirectory() {
	const char* home_env;
#ifdef _WIN32
	home_env = getenv("USERPROFILE");
	if (!home_env) home_env = getenv("HOMEPATH");
#else
	home_env = getenv("HOME");
#endif
	return home_env ? std::filesystem::path(home_env) : std::filesystem::path();
}

std::string f_file_文档转字符串(const S_文档文本& doc) {
	std::u16string 中间字符串;

	for (auto& e : doc.m_文本块) {
		中间字符串 += e.m_一行 + u'\n';
	}

    return f_str_u16_to_u8(中间字符串);
}







